$(function () {
    initEvent();
    if (common.get('task_id')) {
        $('#task_id').val(common.get('task_id'));
    }
    if (common.get('task_stage')) {
        $('#task_stage').val(common.get('task_stage'));
    }
});

function initEvent() {
    $("#J_getCode").off('click').on('click', function () {
        tele_Phonecode();
    });
    $("#submitMsg").off('click').on('click', function () {
        submitMsg();
    });
}

function submitMsg() {
    var yysInfo = common.formatFormData('yysInfo');
    if (!checkParams(yysInfo))
        return false;

    var datas = {
        interface:'users@acquireYys', 
        task_stage: $('#task_stage').val(),
        task_id:$('#task_id').val(),
    };
    if($('#user_pass').val()){
        datas.user_pass = $('#user_pass').val();
    }else if($('#sms_code').val()){
        datas.sms_code = $('#sms_code').val();
    }else if($('#task_id').val()){
        datas.task_id = $('#task_id').val();
    }

    common.ajax({
        data: datas,
        success: function (data) {
            if (data.status == '2000') {
                $("#J_getCode").attr("disabled",true);
                common.clearCountDown($("#J_getCode"));
                common.countDown($("#J_getCode"));
                location.href = data.result.jumpUrl;
            } else if (data.status == '5000') {
                if(data.result.jumpUrl){
                    falert(data.msg,data.result.jumpUrl);
                }else{
                    falert(data.msg);
                }
            }
        }
    });  
}

/*短信验证码验证*/
function tele_Phonecode() {
    var task_id = $('#task_id').val();
    
    var datas = {
        interface:'users@sendSmsCode', 
        task_id: task_id
    };
    common.ajax({
        data: datas,
        beforeSend: function () {
            $("#J_getCode").attr("disabled",true);
            common.clearCountDown($("#J_getCode"));
            common.countDown($("#J_getCode"));
        },
        success: function (data) {
            if (data.status == '2000') {
               $("#J_getCode").attr('disabled',false);
            }
        }
    });
}
